package com.example.demo.story.impl;

import com.example.demo.story.NetStoryServiceAbstract;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.util.Objects;

/**
 * @Author TCJ
 * @create 2024/6/27
 */
public class ks26Impl extends NetStoryServiceAbstract {
	@Override
	public String getBaseUrl() {
		return "http://www.26ks.cc";
	}

	@Override
	public String getReadUrl() {
		return getBaseUrl() + "/book/18623/";
	}

	@Override
	public void analysisChapter() {
		Document html = super.getHtml(getReadUrl());
		Element list = html.body().getElementById("list");
		dto.setTitle("全民--");
		assert list != null;
		Elements dl = list.getElementsByTag("dl");
		boolean start =false;
		for (Element element : dl.get(0).children()) {
			if ("dt".equals(element.tag().getName())){
				if (element.text().contains("正文")){
					start = true;
					continue;
				}
			}
			if (start){
				Elements a = element.getElementsByTag("a");
				super.dto.getChapter().put(a.text(), getBaseUrl() +  a.attr("href"));
			}

		}
	}

	@Override
	public String getContent(String url) {
		StringBuilder sb = new StringBuilder();
		Document html = super.getHtml(url);
		Element content = html.body().getElementById("content");
		assert content != null;
		Elements p = content.getElementsByTag("p");
		for (Element element : p) {
			sb.append(element).append("\r\n");
		}
		return sb.toString();
	}
}
